﻿#include "SEACavityWapper.h"
#include "FITK_Kernel/FITKAppFramework/FITKMessage.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsPhysics.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsMaterial.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsShellPhysicsProp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsNCT.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsSpectraManager.h"
#include "OperatorsInterface/GraphEventOperator.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"

SEACavity* SEACavityWapper::new_SEACavity()
{
    SEACavity* cavity = new SEACavity;
    this->initShell(cavity);
    return cavity;
}

void SEACavityWapper::delete_SEACavity(SEACavity * obj)
{
    if (obj) delete obj;
    //渲染层显示数据
    EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
    if (graphOper == nullptr)return;
    graphOper->updateSEASubSystems();
}

SEACavity * SEACavityWapper::static_SEACavity_GetSEACavity(const QString & name)
{
    SEACavity* cavity = new SEACavity(name);
    this->initShell(cavity);
    return cavity;
}

void SEACavityWapper::addShell(SEACavity * obj, const QString& shellName)
{
    if (!obj)return;
    bool ok = obj->addShell(shellName);
    if (!ok) {
        AppFrame::FITKMessageError("Add Shell failed !");
    }
}

void SEACavityWapper::createCavity(SEACavity * obj)
{
    if (!obj)return;
    bool ok = obj->createCavity();
    if (!ok) {
        AppFrame::FITKMessageError("Creat Cavity failed !");
    }
    else
    {
        //渲染层显示数据
        EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
        if (graphOper == nullptr)return;
        int objID = obj->getCavityID();
        graphOper->updateGraph(objID, true);

    }
}

QString SEACavityWapper::getName(SEACavity * obj)
{
    if (obj)
        return obj->getName();
    return QString();
}

void SEACavityWapper::setName(SEACavity * obj, const QString & name)
{
    if (!obj)return;
    bool ok = obj->setName(name);
    if (!ok) {
        AppFrame::FITKMessageError("Set Name failed !");
    }
}

void SEACavityWapper::setFiuld(SEACavity * obj, const QString & name)
{
    if (!obj)return;
    bool ok = obj->setFiuld(name);
    if (!ok) {
        AppFrame::FITKMessageError("Set Fiuld failed !");
    }
}

void SEACavityWapper::setDamping(SEACavity * obj,const QString & damping)
{
    if (!obj)return;
    bool ok = obj->setDamping(damping);
    if (!ok) {
        AppFrame::FITKMessageError("Set Damping failed !");
    }
}

int SEACavityWapper::getNCT_In_or_Out(SEACavity * obj, const QString & name)
{
    if (obj) return obj->getNCT_In_or_Out(name);
    return -1;
}

void SEACavityWapper::setGeometryProp(SEACavity * obj, int type, bool is, double overridee)
{
    if (!obj)return;
    bool ok = obj->setGeometryProp(type, is, overridee);
    if (!ok) {
        AppFrame::FITKMessageError("Set Override failed !");
    }
}

void SEACavityWapper::setSEAMatrixSolution_ModalDensity(SEACavity * obj, bool isSolution, bool isModalDensity, const QString & modalDensity)
{
    if (!obj)return;
    obj->setSEAMatrixSolution(isSolution);
    bool ok = obj->setModalDensity(isModalDensity, modalDensity);
    if (!ok) {
        AppFrame::FITKMessageError("Set Modal Density failed !");
    }
}

QString SEACavityWapper::getGeometryProp(SEACavity * obj, int overridee)
{
    if (obj)  return obj->getGeometryProp(overridee);
    return QString();
}

void SEACavityWapper::initShell(SEACavity * cavity)
{
    if (cavity == nullptr) return;
    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return;

    Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
    Acoustics::FITKAcousticsSpectraManager* specMgr = phy->getFITKAcousticsSpectraManager();
    Acoustics::FITKAcousticsNCTManager* nctMgr = phy->getFITKAcousticsNCTManager();
    Acoustics::FITKAcousticsPhysicsPropManager* propMgr = phy->getPhysicsPropManager();

    cavity->setMaterialManager(matMgr);
    cavity->setSpectraMgr(specMgr);
    cavity->setNCTMgr(nctMgr);
    cavity->setPropertyManager(propMgr);

}

SEACavity::SEACavity(const QString& name) :
    Acoustics::PyFITKSEACavity(name)
{

}
SEACavity::SEACavity() :
    Acoustics::PyFITKSEACavity()
{

}
